self.onmessage = function(event) {
    const { action, interval, startIndex, length } = event.data
    let counter = startIndex
    if (action === 'start') {
        self.postMessage({ type: 'step', index: 0 })
        // 开始定时任务
        self.intervalId = setInterval(() => {
            if (counter >= length) {
                counter = 0
                self.postMessage({ type: 'step', index: counter })
                counter++
            } else {
                self.postMessage({ type: 'step', index: counter })
                counter++
            }

        }, interval);
    } else if (action === 'stop') {
        counter = 0
        // 停止定时任务
        clearInterval(self.intervalId)
    }
};